package com.mzj.saas.admin;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.HouseBanner;
import com.haixiaoke.saas.repository.service.IHouseBannerService;
import com.mzj.saas.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 公众号首页轮播图Controller
 *
 * @author qixi
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/admin/houseBanner")
public class AdminOpHouseBannerController extends BaseController {
    @Autowired
    private IHouseBannerService houseBannerService;

    @Autowired
    private LoginUserUtil loginUserUtil;

    /**
     * 查询公众号首页轮播图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseBanner houseBanner) {
        startPage();
        houseBanner.setOrgId(loginUserUtil.getOrgId());
        List<HouseBanner> list = houseBannerService.selectHouseBannerList(houseBanner);
        return getDataTable(list);
    }

    /**
     * 查询公众号首页轮播图列表
     */
    @GetMapping("/user/list")
    public TableDataInfo usesList(HouseBanner houseBanner) {
        startPage();
        List<HouseBanner> list = houseBannerService.selectHouseBannerList(houseBanner);
        return getDataTable(list);
    }

    // /**
    //  * 导出公众号首页轮播图列表
    //  */
    // @PostMapping("/export")
    // public void export(HttpServletResponse response, HouseBanner houseBanner) {
    //     List<HouseBanner> list = houseBannerService.selectHouseBannerList(houseBanner);
    //     ExcelUtil<HouseBanner> util = new ExcelUtil<HouseBanner>(HouseBanner.class);
    //     util.exportExcel(response, list, "公众号首页轮播图数据");
    // }

    /**
     * 获取公众号首页轮播图详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(houseBannerService.selectHouseBannerById(id));
    }

    /**
     * 新增公众号首页轮播图
     */

    @PostMapping
    public AjaxResult add(@RequestBody HouseBanner houseBanner) {
        houseBanner.setOrgId(loginUserUtil.getOrgId());
        houseBanner.setCreateBy(loginUserUtil.getId());
        return toAjax(houseBannerService.insertHouseBanner(houseBanner));
    }

    /**
     * 修改公众号首页轮播图
     */
    @PutMapping
    public AjaxResult edit(@RequestBody HouseBanner houseBanner) {
        return toAjax(houseBannerService.updateHouseBanner(houseBanner));
    }

    /**
     * 删除公众号首页轮播图
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(houseBannerService.deleteHouseBannerByIds(ids));
    }
}
